<?php

namespace common\models\db;

use Yii;

/**
 * This is the model class for table "tbl_principal_result".
 *
 * @property int $id
 * @property int $record_id 关联的贷款记录ID
 * @property float $total_loan 贷款总额(元)
 * @property float $total_repayment 还款总额(元)
 * @property float $total_interest 总利息(元)
 * @property float $first_month_payment 首月还款(元)
 * @property float $decrease_per_month 每月递减(元)
 * @property float $last_month_payment 末月还款(元)
 *
 * @property LoanRecord $loanRecord
 */
class PrincipalResult extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'tbl_principal_result';
    }

    /**
     * {@inheritdoc}
     */
    public function attributes()
    {
        return [
            'id',
            'record_id',
            'total_loan',
            'total_repayment',
            'total_interest',
            'first_month_payment',
            'decrease_per_month',
            'last_month_payment'
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['record_id', 'total_loan', 'total_repayment', 'total_interest', 'first_month_payment', 'decrease_per_month', 'last_month_payment'], 'required'],
            [['record_id'], 'integer'],
            [['total_loan', 'total_repayment', 'total_interest', 'first_month_payment', 'decrease_per_month', 'last_month_payment'], 'number'],
            [['record_id'], 'unique'],
            [['record_id'], 'exist', 'skipOnError' => true, 'targetClass' => LoanRecord::class, 'targetAttribute' => ['record_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'record_id' => 'Loan Record ID',
            'total_loan' => 'Total Loan',
            'total_repayment' => 'Total Repayment',
            'total_interest' => 'Total Interest',
            'first_month_payment' => 'First Month Payment',
            'decrease_per_month' => 'Decrease Per Month',
            'last_month_payment' => 'Last Month Payment',
        ];
    }

    /**
     * Gets query for [[LoanRecord]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getLoanRecord()
    {
        return $this->hasOne(LoanRecord::class, ['id' => 'record_id']);
    }
}
